﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitTest.Mock;

using aQuery;

namespace UnitTest
{
    [TestClass]
    public class ActionQueueTest
    {
        [TestMethod]
        public void ShouldDequeueWorks()
        {
            Conta c = new Conta(10);
            var queue = c.EnqueueAction(x => x.Withdraw(5)).EnqueueAction(x => x.Withdraw(3)).EnqueueAction(x => x.Withdraw(1));
            Assert.AreEqual(c.Money, 10);
            
            queue.DequeueAction();
            Assert.AreEqual(c.Money, 5);

            queue.DequeueAction();
            Assert.AreEqual(c.Money, 2);

            queue.DequeueAction();
            Assert.AreEqual(c.Money, 1);
        }

        [TestMethod]
        public void ShouldExecuteQueueWorks()
        {
            Conta c = new Conta(10);
            c.EnqueueAction(x => x.Withdraw(1)).EnqueueAction(x => x.Withdraw(2)).EnqueueAction(x => x.Withdraw(3)).ExecuteQueue();
            Assert.AreEqual(c.Money, 4);
        }

        [TestMethod]
        public void ShouldSkipWorks()
        {
            Conta c = new Conta(10);
            c.EnqueueAction(x => x.Withdraw(5)).EnqueueAction(x => x.Withdraw(3)).SkipAction().DequeueAction();
            Assert.AreEqual(c.Money, 7);
        }

        [TestMethod]
        public void ShouldLazyDequeueWorks()
        {
            Conta c = new Conta(0);
            var queue = c.EnqueueAction(x => x.Withdraw(5)).EnqueueAction(x => x.Withdraw(3));
            c.Money = 10;
            queue.DequeueAction();
            Assert.AreEqual(c.Money, 5);
            queue.EnqueueAction(x => x.Withdraw(2)).ExecuteQueue();
            Assert.AreEqual(c.Money, 0);
        }
    }
}
